package com.example.shop_2212.adapter

import android.widget.RatingBar
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.Comment
import com.example.shop_2212.R
import com.example.shop_2212.utils.GlideUtils

class CommentAdapter:BaseQuickAdapter<Comment,BaseViewHolder>(R.layout.item_comment) {
    override fun convert(holder: BaseViewHolder, item: Comment) {
        GlideUtils.loadCircleImage(context,item.avatar,holder.getView(R.id.comment_iv))//用户头像
        holder.setText(R.id.comment_name,item.nickname)//用户名称
        holder.getView<RatingBar>(R.id.comment_rb).rating = item.score.toFloat()//评分小星星
        holder.setText(R.id.comment_content,item.comment)//评论文字
        holder.setText(R.id.comment_time,item.createTime)//评论时间
        val rv = holder.getView<RecyclerView>(R.id.comment_rv)//评论图片
        val imgAdapter = ImgAdapter()
        imgAdapter.data.clear()
        imgAdapter.data.addAll(item.pics)
        rv.adapter = imgAdapter
        rv.layoutManager = GridLayoutManager(context,3)
    }
}

class ImgAdapter:BaseQuickAdapter<String,BaseViewHolder>(R.layout.item_comment_img){
    override fun convert(holder: BaseViewHolder, item: String) {
        GlideUtils.loadImage(context,item,holder.getView(R.id.iv))
    }

}